package com.tsd.system.controller;

import com.tsd.common.controller.BaseController;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.ErrorCode;
import com.tsd.core.vo.HttpResult;
import com.tsd.system.service.WxSettingService;
import com.tsd.system.vo.MiniappSetting;
import com.tsd.system.vo.MpSetting;
import com.tsd.system.vo.OpenSetting;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @ClassName: WxSettingController
 * @Description: TODO
 * @Author: Hillpool
 * @Date: 2022/7/6 16:25
 * @Version: 1.0
 */
@Controller
@Scope("prototype")
@RequestMapping("/api/v2")
@Api(tags = "微信配置", description = "微信配置的API描述")
public class WxSettingController extends BaseController {

    @Resource
    private WxSettingService wxSettingService;

    @ResponseBody
    @RequestMapping(value = "/clearWxSettingCache.action", method = RequestMethod.POST)
    public HttpResult<Object> clearWxLoginCache() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            String type = HlpUtils.getString(map, "type");
            super.checkEmpty(type, "缺少参数：type");
            if (OpenSetting.SETTING_CODE_WX_OPEN.equals(type)) {
                wxSettingService.clearWxOpenCache();
            } else if (MpSetting.SETTING_CODE_WX_MP.equals(type)) {
                wxSettingService.clearWxMpCache();
            } else if (MiniappSetting.SETTING_CODE_WX_MINIAPP.equals(type)) {
                wxSettingService.clearWxMiniappCache();
            }
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }
}
